Effective inventory control for coffee-vending machines hinges on anticipating weekly ingredient consumption while avoiding costly spoilage. We forecast demand using historical sales from two machines, delivering eight-week projections that guide stock levels and reorder cadence.
This report:
Imports & cleans transaction data from two coffee-vending machines.
Explores key demand drivers.
Models weekly sales with Seasonal ARIMA (plus Prophet as a benchmark).
Delivers eight-week forecasts and stocking recommendations.
Data Input and Combining
Kaggle data is from two vending machines. Below we will import the two datasets and combine them.
Raw Transaction Data
Transaction data was taken from the following Kaggle link:
In the dataset, only product names are given. In order to more accurately predict what ingredients are needed and when, we must decompose the product into its ingredients. See below for the assumptions made for each of the 8 unique products.
Below we will join the two tables on the coffee name, which will add ingredients to all rows in the transaction data. Explore the data we will use in our analysis below:
We aggregate to a weekly time series because the business decisions we are informing, like re-ordering coffee, milk, chocolate, etc, are made on a weekly cadence. Collapsing daily transactions into weeks smooths out erratic, day-to-day swings leaving a cleaner signal that aligns directly with the quantity we must predict.
We will also convert to a time series type object and verify it has no gaps in the series. If we see FALSE from .gaps, then we have no gaps.
#checking Autocorrelation of each ingredientsweekly_long %>%# your original data-frame filter(metric !="sales_n") %>%# keep the same exclusiongroup_by(metric) %>%# work metric-by-metricgroup_walk(~{ v <- .x$value v <- v[is.finite(v)] # drop NA / Infif (length(v) <2L ||var(v) ==0) {message("Skipping ", .y$metric, ": not enough finite variation.") } else {acf(v,main =paste("ACF for", .y$metric),na.action = na.pass) # keeps plotting even if a few NA remain } })
#Differencing each ingredientsweekly_diff <- weekly_long %>%filter(metric !="sales_n") %>%group_by(metric) %>%arrange(week) %>%mutate(value_diff =difference(value)) %>%filter(!is.na(value_diff)) %>%ungroup()#ACF for Differenced Ingredientsweekly_diff %>%# your differenced data framegroup_by(metric) %>%# handle one metric at a timegroup_walk(~{ v <- .x$value_diff # pull the differenced vector# 1. keep only finite, non-missing observations v <- v[is.finite(v)]# 2. check that we still have at least two values AND some varianceif (length(v) <2L ||var(v) ==0) {message("Skipping ", .y$metric,": not enough finite variation after differencing.") } else {acf(v,lag.max =30,main =paste("ACF for Differenced", .y$metric),na.action = na.pass) # ignore any intermittent NA gaps } })